﻿#region
/*******************************************************************************
** File Name:		    AliMaMaService.cs
** Creator:		        chao.jiang 
** EMail:               chao.jiang 
** Create date:	        
** Latest Modifier:
** Latest Modify date:
** Description:		    
** Modify History:
**
** Code Review:
**
** Version number:       1.0.0
*********************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Text;
using Phoenix.Service.Contracts;
using Phoenix.Service.Model;
using Phoenix.IBatisRepository;
using Phoenix.Respository;
using System.Data;
using Phoenix.Entity;

namespace Phoenix.Service
{
    public class AliMaMaService : IAliMaMaService
    {
		 IAliMaMa aliMaMa = new AliMaMaRepository();
		 
		 #region  Auto Generation
		 
        public void AddAliMaMa(AliMaMaModel model)
        {
			EAliMaMa entity = ConvertModelToEntity(model);
			
            aliMaMa.AddAliMaMa(entity);
        }

		public void UpdateByMMID (AliMaMaModel model)
		{
			EAliMaMa entity = ConvertModelToEntity(model);

            aliMaMa.UpdateByMMID(entity);

		}

		public void DeleteByMMID (System.Int32 mMID)
		{
		
            aliMaMa.DeleteByMMID(mMID);

		}
		 
        public AliMaMaModel GetByMMID (System.Int32 mMID)
        {
        
			EAliMaMa entity = aliMaMa.GetByMMID(mMID);
			
            AliMaMaModel model = ConvertEntityToModel(entity);


            return model;
        }
        
	
		public IList<AliMaMaModel> GetAll ()
		{
			IList<EAliMaMa> entity = aliMaMa.GetAll();
			
			if (entity == null)
            {
                return null;
            }
            
            IList<AliMaMaModel> list = new List<AliMaMaModel>();

            foreach (var item in entity)
            {
                AliMaMaModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
			
		}
		
		private AliMaMaModel ConvertEntityToModel(EAliMaMa entity)
		{
			if (entity == null)
            {
                return null;
            }
			AliMaMaModel model = new AliMaMaModel();
                        model.MMID = entity.MMID;
                        model.ProductID = entity.ProductID;
                        model.ItemID = entity.ItemID;
                        model.Price = entity.Price;
                        model.Commission = entity.Commission;
                        model.Clicks = entity.Clicks;
                        model.Enable = entity.Enable;
                        model.TaoUrl = entity.TaoUrl;
                        model.UpdateTime = entity.UpdateTime;
                        model.CreateTime = entity.CreateTime;
                        return model;
		}
		
		private EAliMaMa ConvertModelToEntity(AliMaMaModel model)
		{
			if (model == null)
            {
                return null;
            }
			EAliMaMa entity = new EAliMaMa();
                        entity.MMID = model.MMID;
                        entity.ProductID = model.ProductID;
                        entity.ItemID = model.ItemID;
                        entity.Price = model.Price;
                        entity.Commission = model.Commission;
                        entity.Clicks = model.Clicks;
                        entity.Enable = model.Enable;
                        entity.TaoUrl = model.TaoUrl;
                        entity.UpdateTime = model.UpdateTime;
                        entity.CreateTime = model.CreateTime;
                        return entity;
		}
		
		
		
		#endregion

       public  IList<AliMaMaModel> GetByProductID(int productID)
        {

            IList<EAliMaMa> entity = aliMaMa.GetByProductID(productID);

            if (entity == null)
            {
                return null;
            }

            IList<AliMaMaModel> list = new List<AliMaMaModel>();

            foreach (var item in entity)
            {
                AliMaMaModel model = ConvertEntityToModel(item);
                list.Add(model);
            }
            return list;   
        }
    }
}